package com.mxl.mvc.cashorder;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.mxl.dao.cashorder.impl.GatewayPayOrderDaoImpl;
import com.mxl.service.cashorder.dto.CardResultDto;

/**
 * 网关查询页面 接口等
 * 
 * @author xianglin.mo
 * 
 */
public class GatewayQueryController extends MultiActionController {

	private GatewayPayOrderDaoImpl gatewayPayOrderDao;

	// 页面查询根据商家订单号或者卡号 或者 卡密 时间查询 ---商家查询默认时间30天之内 其他的默认7天
	@SuppressWarnings("unchecked")
	public ModelAndView index(final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		// 从页面获取参数
		request.setCharacterEncoding("UTF-8");
		// String cardNo = request.getParameter("cardNo");
		// String cardPwd = request.getParameter("cardPwd");
		// String memberCode = request.getParameter("memberCode");
		// String orderId = request.getParameter("orderId");

		return new ModelAndView("/jsp/query");
	}

	public ModelAndView query(final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		// 从页面获取参数
		request.setCharacterEncoding("UTF-8");
		String cardNo = request.getParameter("cardNo");
		String cardPwd = request.getParameter("cardPwd");
		WebApplicationContext rc = WebApplicationContextUtils
				.getWebApplicationContext(request.getSession()
						.getServletContext());
		List<CardResultDto> dtoList = gatewayPayOrderDao.query(cardNo, cardPwd,
				rc);
		return new ModelAndView("/jsp/cardQueryResult").addObject("list",
				dtoList);
	}

	public void setGatewayPayOrderDao(GatewayPayOrderDaoImpl gatewayPayOrderDao) {
		this.gatewayPayOrderDao = gatewayPayOrderDao;
	}

}
